<%@ page import="cn.yunhe.news.dao.IBoardDao" %>
<%@ page import="cn.yunhe.news.entity.Board" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="cn.yunhe.news.dao.impl.BoardDao" %>
<%@ page import="cn.yunhe.news.FenYe" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/4/2
  Time: 19:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <style type="text/css">
        .main {
            width: 100%;
            height: 100%;
            margin: 0px auto;
        }

        .main_main {
            width: 70%;
            height: 100%;
            margin: 0px auto;
            text-align: center;
            font-size: 25px;
        }

        .main_top {
            width: 100%;
            height: 20%;
            margin-top: 50px;
        }

        input[type="text"] {
            height: 40px;
            font-size: 25px;
        }

        input[type="submit"] {
            height: 40px;
            font-size: 20px;
        }

        input[type="checkbox"] {
            width: 18px;
            height: 18px;

        }

        table {
            text-align: center;
            width: 500px;
            font-size: 20px;
        }
    </style>
    <script type="text/javascript" src="../js/jquery-1.8.3.js"></script>
</head>
<body background="pic/ManBgroud.gif">
<%
    String keyword = "";
    if (request.getAttribute("keyword") != null) {
        keyword = (String) request.getAttribute("keyword");
    }


%>
<div class="main">
    <div class="main_main">
        <div class="main_top">
            <form action="selectzt_action.jsp" method="post">
                请输入关键字:&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="keyword" value="<%=keyword%>">
                <input type="submit" value="搜索">
            </form>
        </div>
        <div class="main_buttom">
            <table border="1" cellspacing="0" cellpadding="0" align="center">
                <tr>
                    <th>全选<input type="checkbox" name="all" id="all"></th>
                    <th>主题编号</th>
                    <th>主题名称</th>
                    <th>主题操作</th>
                </tr>
                <%
                    String pageIn= (String) request.getAttribute("pageIndex");
                    if (pageIn==null){
                        pageIn="1";
                    }
                    int pageIndex = Integer.parseInt(pageIn);

                    IBoardDao boardDao = new BoardDao();

                    //总条数
                    int count = boardDao.allCount();
                    //总页数
                    int pageSize = FenYe.pageSize(count, FenYe.pageNum);

                    if (pageIndex < 1) {
                        pageIndex = 1;
                    }
                    if (pageIndex > pageSize) {
                        pageIndex = pageSize;
                    }


                    //全部查
                    List<Board> boardList = boardDao.boardFList(FenYe.pageNum, pageIndex);


                    List<Board> allList = new ArrayList<Board>();

                    //关键字查
                    List<Board> keyList = (List<Board>) request.getAttribute("keyList");

                    if (keyList != null) {
                        allList = keyList;
                    } else {
                        allList = boardList;
                    }

                    for (Board b : allList) {
                %>
                <tr>
                    <td>
                        <input type="checkbox" name="one" class="one">
                    </td>
                    <td>
                        <%=b.getBid()%>
                    </td>
                    <td>
                        <%=b.getBname()%>
                    </td>
                    <td>
                        <a href="#">修改</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="delBoard.jsp?bid=<%=b.getBid()%>"
                                                                      class="del">删除</a>
                    </td>
                </tr>
                <%
                    }
                %>
                <tr>
                    <td colspan="3">
                        <a href="selectzt_action.jsp?pageIndex=1">首页</a>
                        <a href="selectzt_action.jsp?pageIndex=<%=pageIndex-1%>">上一页</a>
                        <a href="selectzt_action.jsp?pageIndex=<%=pageIndex+1%>">下一页</a>
                        <a href="selectzt_action.jsp?pageIndex=<%=pageSize%>">尾页</a>
                    </td>
                    <td>
                        <a href="">删除所选</a>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>
</body>
<script>

    $(function () {
        //全选
        $("#all").click(function () {
            var $flag = $(this).is(":checked");
            $("input[name='one']").each(function () {
                $(this).attr("checked", $flag);
            })

        })

        //反全选
        $(".one").click(function () {
            var count = 0;
            $(".one").each(function () {
                if ($(this).is(":checked")) {
                    count++;
                }
            })
            if (count == $(".one").size()) {
                $("#all").attr("checked", true);
            } else {
                $("#all").attr("checked", false);
            }
        })

    })
</script>
</html>
